<script type="text/javascript">
    $(function () {
        var selectedGrid = $("#search-kh-selected-kh-grid").edatagrid({
            fitColumns:false,
            rownumbers:true,
            singleSelect:true,
            pageNumber:1,
            fit:true,
            frozenColumns:[
                [
                    {field:'jtwz_oldcode', title:'老物资编码', hidden:true},
                    {field:'jtwz_code', title:'物资编码', width:100},
                    {field:'jtwz_name', title:'物资名称', width:90},
                    {field:'jtwz_ggxh', title:'规格型号', width:80},
                    {field:'js', title:'件数', width:80},
                    {field:'sl', editor:{type:'numberbox', options:{min:0, groupSeparator:',', precision:4}}, title:'数量',
                        formatter:function (value) {
                            var sl = formatSlForHtml(value, ",");
                            return sl;
                        }, width:80},
                    {field:'kkdsl', title:'可开单数量', formatter:function (value) {
                        var sl = formatSlForHtml(value, ",");
                        return sl;
                    }, width:80},
                    {field:'rkrq', title:'入库日期', width:100}
                ]
            ],
            columns:[
                [
                    {field:'cd_z', title:'产地', width:60},
                    {field:'jtwz_dw', title:'单位', width:40},
                    {field:'jtwz_th', title:'图号', width:120},
//                    {field:'kcbj', title:'库存报价', formatter:function (value) {
//                        var sl = formatJeForHtml(value, ",");
//                        return sl;
//                    }, width:80},
//                    {field:'wsdj', title:'成本价格', formatter:function (value) {
//                        var sl = formatJeForHtml(value, ",");
//                        return sl;
//                    }, width:80},
                    {field:'ck_mc', title:'仓库', width:100},
                    {field:'khbm', title:'卡号编码', width:150}
                ]
            ],
            onSelect:function (rowIndex, rowData) {
                //获取每个单元格
                $("#search-kh-selected-kh-grid").edatagrid('editRow', rowIndex);
                var editors = $("#search-kh-selected-kh-grid").datagrid('getEditors', rowIndex);
                if (editors.length == 0)
                    return;
            },
            onRowContextMenu:function (e, rowIndex, rowData) {
                e.preventDefault();
                $('#search-kh-menu').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                }).data("rowIndex", rowIndex);
            }
        });

        $("#kh-grid").edatagrid({
            url:$.webPath() + '/xsgl/khgl/khList?ckid=' + $("#ckid").val() + '&xsgsId=' + $("#xsgsId").val() + '&sbgsId=' + $("#sbgsId").val() + '&cdid=' + $("#cdid").val() + '&wzggid=' + $("#wzggid").val(),
            fitColumns:false,
            singleSelect:true,
            toolbar:"#search-kh-toolbar",
            fit:true,
            pagination:true,
            checkOnSelect:false,
            selectOnCheck:false,
            pageNumber:1,
            rownumbers:true,
            frozenColumns:[
                [
                    {field:'jtwz_oldcode', title:'老物资编码', hidden:true},
                    {field:'jtwz_code', title:'物资编码', width:100},
                    {field:'jtwz_name', title:'物资名称', width:90},
                    {field:'jtwz_ggxh', title:'规格型号', width:80},
                    {field:'js',title:'件数',width:80},
                    {field:'sl', editor:{type:'numberbox', options:{min:0, groupSeparator:',', precision:4}}, title:'数量',
                        formatter:function (value) {
                            var sl = formatSlForHtml(value, ",");
                            return sl;
                        }, width:80},
                    {field:'kkdsl', title:'可开单数量', formatter:function (value) {
                        var sl = formatSlForHtml(value, ",");
                        return sl;
                    }, width:80},
                    {field:'rkrq', title:'入库日期', width:100}
                ]
            ],
            columns:[
                [
                    {field:'cd_z', title:'产地', width:60},
                    {field:'jtwz_dw', title:'单位', width:40},
                    {field:'jtwz_th', title:'图号', width:120},
//                    {field:'kcbj', title:'库存报价', formatter:function (value) {
//                        var sl = formatJeForHtml(value, ",");
//                        return sl;
//                    }, width:80},
//                    {field:'wsdj', title:'成本价格', formatter:function (value) {
//                        var sl = formatJeForHtml(value, ",");
//                        return sl;
//                    }, width:80},
                    {field:'ck_mc', title:'仓库', width:100},
                    {field:'khbm', title:'卡号编码', width:150}
                ]
            ],
            onSelect:function (rowIndex, rowData) {
                var data = $("#search-kh-selected-kh-grid").datagrid('getData');
                if (data.rows.length > 0) {
                    $.messager.alert("提示", "仅限选择一条卡号", "info");
                } else {
//                    rowData.sl = 0.0000;
                    $(selectedGrid).datagrid('appendRow', rowData);
                }
            }
        });

        $("#search-kh-menu").menu({
            onClick:function (item) {
                if (item.name == "delete")
                    $("#search-kh-selected-kh-grid").datagrid('deleteRow', $(this).data("rowIndex"));
            }
        });

        $("#btn_kh_search").click(function () {
            $('#kh-grid').edatagrid({
                url:$.webPath() + '/xsgl/khgl/khList?ckid=' + $("#ckid").val() + '&cdid=' + $("#cdid").val() + '&wzggid=' + $("#wzggid").val(),
                pageNumber:1,
                queryParams:{
                    khbm:$('#khbm').val(),
                    wzbm:$("#wzbm").val(),
                    jtwzname:$('#jtwz_name').val(),
                    jtwzggxh:$("#jtwz_ggxh").val()
                },
                onSelect:function (rowIndex, rowData) {
                    var data = $("#search-kh-selected-kh-grid").datagrid('getData');
                    if (data.rows.length > 0) {
                        $.messager.alert("提示", "仅限选择一条卡号", "info");
                    } else {
                        rowData.sl = 0.0000;
                        $(selectedGrid).datagrid('appendRow', rowData);
                    }
                }
            });
        });
    })
</script>
<input type="hidden" id="ckid" value="${(ckid)!}"/>
<input type="hidden" id="xsgsId" value="${(xsgsId)!}"/>
<input type="hidden" id="sbgsId" value="${(sbgsId)!}"/>
<input type="hidden" id="cdid" value="${(cdid)!}"/>
<input type="hidden" id="wzggid" value="${(wzggid)!}"/>
<div class="easyui-layout" data-options="fit:true">

    <div data-options="region:'north',split:true" style="height:375px">
        <div id="search-kh-toolbar" style="height:auto">
            <div class="textcon">
                <table class="tb" style="margin-left: 12px;">
                    <tr>
                        <th>卡号编码:</th>
                        <td>
                            <input id="khbm" type="text" name="khbm" class="input-text">
                        </td>
                        <th>物资编码:</th>
                        <td>
                            <input id="wzbm" type="text" name="wzbm" class="input-text">
                        </td>
                        <th>规格型号:</th>
                        <td>
                            <input id="jtwz_ggxh" type="text" name="jtwzggxh" class="input-text">
                        </td>
                        <td style=" padding-left:5px;">
                            <input id="btn_kh_search" type="button" value="" class="submit" plain="true"/>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <table id="kh-grid">
        </table>
    </div>
    <div data-options="region:'center'">
        <table id="search-kh-selected-kh-grid">
        </table>
        <div id="search-kh-menu" class="easyui-menu" style="width:120px;">
            <div name="delete">删除</div>
        </div>
    </div>
</div>